<template>
    <el-dialog v-model="isDialogFormVisible" title="编辑">
        <el-form @submit.native.prevent v-for="item in props.bgcolumnNames  " :model="editItem">
            <el-form-item v-if="item.IsEditable" :label="item.Label">
                <span v-if="item.ControlType == 1">
                    <JSCodeMirror v-model:value="editItem[item.Name]"></JSCodeMirror>
                </span>
                <el-input v-else v-model="editItem[item.Name]" autocomplete="off" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="close">取消</el-button>
                <el-button type="primary" @click="onConfirm">
                    确定
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>


<script lang="ts" setup>
import { ref, reactive, computed } from 'vue';
import JSCodeMirror from '../components/JSCodeMirror.vue'; // 引入 CodeEditor 组件
const isDialogFormVisible = ref(false)
var editItem = reactive({});
const emit = defineEmits(['confirm']);

// props 接收父组件传过来的
const props = defineProps({
    bgcolumnNames: Array as () => any[]
})
const close = () => {
    isDialogFormVisible.value = false
}

const open = (item) => {
    isDialogFormVisible.value = true
    console.log('open', item)
    editItem = reactive(item)
}
var onConfirm = () => {
    emit("confirm", editItem)
}

defineExpose({ open, close });

</script>
